package com.example.springboot.common;

import lombok.Data;

@Data
public class Result {
    private  static  final String SUCCESS_CODE = "200";
    private  static  final String ERROR_CODE = "-1";

//    这三个属性 就是我们要返回给前端的所有属性了
    private String code; // 接口的响应结果 可以存储在code
    private Object data;
    private String msg;  // 存放错误信息

    public static Result success() {
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        return result;
    }

//    新增成功了 但是不返回数据 查询成功了 但是需要返回数据 所以有两个success方法
    public  static Result success(Object data) {
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setData(data);
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMsg(msg);
        return result;
    }

    public static Result error(String code,String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
